import Clipboard from "clipboard";
import { showToast } from "vant";

export function clipboard(e, text) {
  const clipboard = new Clipboard(e.target, { text: () => text });
  clipboard.on("success", () => {
    showToast("复制成功");
    // 释放内存
    clipboard.off("error");
    clipboard.off("success");
    clipboard.destroy();
  });
  clipboard.on("error", () => {
    // 不支持复制
    showToast("复制失败");
    // 释放内存
    clipboard.off("error");
    clipboard.off("success");
    clipboard.destroy();
  });
  clipboard.onClick(e);
}
